package com.jframe.sys.controller.utils;

import com.jframe.sys.controller.listener.ActionListener;

public class TaskThread extends Thread {

	private boolean stopThread;
	
	private String name="";
	private String action = "";
	private String method = "";
	private Object[] args = {};
	private long sleep = 0; //单位毫秒
	private TaskThread() {
		this.stopThread = false;
	}
	
	public TaskThread(String name,String action,String method,Object[] args,long sleep){
		
		this.name = name;
		this.action = action;
		this.method = method;
		this.args =args;
		this.sleep = sleep;
	}
    
	public void run() {
		// 线程启动啦
		System.out.println(name + "任务线程启动了");
		if("".equals(action) || "".equals(method) || sleep <=0){
			this.stopThread();
		}
		while (!(this.stopThread)) {			
			ActionListener.threadTask(action, method, args);						
			try {
				TaskThread.sleep(sleep);
			} catch (InterruptedException e) {
			}
		}
	}

	public void stopThread() {
		this.stopThread = true;
		System.out.println("线程休息了....");
		
	}

}
